package com.hdp.kotlin_samples.middle

/**
 * author:hdp
 * on:2019/6/13:9:27
 *
 * kotlin 类结构简介：
 *
 * 1、构造函数的执行顺序：
 *      1、主构造函数指跟在类名后的那一部分，
 *      2、init代码块可以看做是主构造函数的一部分，
 *      3、构造函数执行顺序：父类主构造函数->init ->父类次构造函数->子类构造函数->子init块 ->子类次构造函数
 *
 *
 * */

fun main() {
    val animal = Dog("小名", 30)
    animal.eat()
    println(animal)
}

open class Animal(myname: String? = null) {

     var legs: String="123"

    init {
        legs.length
        print("Animal init ${myname}\n")
    }

    constructor(name: String, age: Int) : this(name) {
        print("Animal second\n")
    }

    open fun eat() {
        println("super eat")
    }

}

class Dog : Animal {
    private val str = "Dog"


    constructor(name: String) : super(name) {
        println("Dog first")
    }

    init {
        println("Dog init")
    }

    override fun eat() {
        println("dog eat")
    }


    constructor(name: String, age: Int) : super(name, age) {
        println("Dog second")
    }
}


